//
//  NSString+YDYExtension.m
//  DYSisterAPP
//
//  Created by 杨德勇 on 16/8/4.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "NSString+YDYExtension.h"

@implementation NSString (YDYExtension)



-(unsigned long long)ydy_fileSize{
    
    unsigned long long size = 0;
    
    NSFileManager *mgr = [NSFileManager defaultManager];
    //判断是不是文件夹
    BOOL isDirectory = NO;
    
    //判断路径是否存在
    BOOL isExist = [mgr fileExistsAtPath:self isDirectory:&isDirectory];
    if (!isExist) {
        return 0;
    }
    if (isDirectory) {
        NSDirectoryEnumerator *enumerator = [mgr enumeratorAtPath:self];
        for (NSString *subpath  in enumerator) {
            NSString *fullpath = [self stringByAppendingPathComponent:subpath];
            size  +=[mgr attributesOfItemAtPath:fullpath error:nil].fileSize;
        }
    }else{
        //传进来的是一个文件，不是文件夹
        size = [mgr attributesOfItemAtPath:self error:nil].fileSize;
    }
    return size;
}
@end
